<?php
// 连接数据库
$host = 'localhost';
$user = 'root';
$pwd = '123456';
$dbname = 'business';

// 创建数据库连接对象
$db = new mysqli($host, $user, $pwd, $dbname);

// 检查连接是否成功
if ($db->connect_errno) {
    die("连接数据库失败: " . $db->connect_error);
}

// 设置字符集为 UTF-8
$db->set_charset('utf8');

// 获取表单提交的数据
$id = $_POST['id'];
$sname = $_POST['sname'];
$sprice = $_POST['sprice'];
$sdes = $_POST['sdes'];
$slocation = $_POST['slocation'];
$svar = $_POST['svar'];
$Gphone = $_POST['Gphone'];
$Gbrand = $_POST['Gbrand'];
$Gwechat = $_POST['Gwechat'];

// 更新商品信息的 SQL 语句
$sql = "UPDATE commodity SET Gname='$sname', Gprice='$sprice', 
                     Gdescription='$sdes', Glocation='$slocation', 
                     Gclass='$svar', Gphone='$Gphone', Gbrand='$Gbrand', 
                     Gwechat='$Gwechat' WHERE Gid='$id'";

// 执行 SQL 语句
if ($db->query($sql) === TRUE) {
    echo "商品信息更新成功";
} else {
    echo "Error: " . $sql . "<br>" . $db->error;
}

// 关闭数据库连接
$db->close();
?>
